<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tab {
            width: 590px;
            height: 340px;
            margin: 20px;
            border: 1px solid #e4e4e4;
        }

        .tab-nav {
            width: 100%;
            height: 60px;
            line-height: 60px;
            display: flex;
            justify-content: space-between;
        }

        .tab-nav h3 {
            font-size: 24px;
            font-weight: normal;
            margin-left: 20px;
        }

        .tab-nav ul {
            list-style: none;
            display: flex;
            justify-content: flex-end;
        }

        .tab-nav ul li {
            margin: 0 20px;
            font-size: 14px;
        }

        .tab-nav ul li a {
            text-decoration: none;
            border-bottom: 2px solid transparent;
            color: #333;
        }

        .tab-nav ul li a.active {
            border-color: #e1251b;
            color: #e1251b;
        }

        .tab-content {
            padding: 0 16px;
        }

        .tab-content .item {
            display: none;
        }

        .tab-content .item.active {
            display: block;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab-nav">
            <h3>每日特价</h3>
            <ul>
                <li><a class="active" href="javascript:;" data-i="0">精选</a></li>
                <li><a href="javascript:;" data-i="1">美食</a></li>
                <li><a href="javascript:;" data-i="2">百货</a></li>
                <li><a href="javascript:;" data-i="3">个护</a></li>
                <li><a href="javascript:;" data-i="4">预告</a></li>
            </ul>
        </div>
        <div class="tab-content">
            <div class="item active"><img src="./images/tab00.png" alt="" /></div>
            <div class="item"><img src="./images/tab01.png" alt="" /></div>
            <div class="item"><img src="./images/tab02.png" alt="" /></div>
            <div class="item"><img src="./images/tab03.png" alt="" /></div>
            <div class="item"><img src="./images/tab04.png" alt="" /></div>
        </div>
</body>

</html>
<script>
    // 需求：事件委托来实现tab栏切换
    const ul = document.querySelector('.tab-nav ul')
    const items = document.querySelectorAll('.item')
    // 需求1：鼠标经过高度
    // 1.1 获取到ul 给他绑定mouseover事件（有冒泡）
    ul.addEventListener('mouseover', function (e) {
        // 1.2判断 事件目标是否是a标签
        if (e.target.tagName === 'A') {
            console.log(e.target);
            // 1.3排他思想实现高亮
            ul.querySelector('.active').classList.remove('active')
            e.target.classList.add('active')
            // 获取自定义属性: 元素对象.dataset.属性名
            console.log(e.target.dataset.i);
            const i = e.target.dataset.i
            // 通过索引找到对应的大盒子, 排他思想
            document.querySelector('.tab-content .active').classList.remove('active')
            items[i].classList.add('active')


        }
    })
</script>